package com.example.jetpackcomposelayouts

import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.Divider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

/**
 * @author huangzehui
 * @date 2/5/2024 下午6:18 周四
 * @description
 *
 * https://www.bilibili.com/video/BV1ob4y1a7ad/?p=24&spm_id_from=pageDriver&vd_source=e07cc8cc94eb22bd76722071b03cd199
 *
 * Compose 不允许多次测量，如果需要在绘制前指定控件的最大最小值，可以使用 Intrinsics 来获取
 *
 * Compose 只测量子元素一次，测量两次会引发运行时异常。但是，有时在测量
 * 子元素之前，我们需要一些有关子元素的信息。
 */


@Composable
fun TwoTexts(modifier: Modifier = Modifier) {
    Row(modifier = modifier.height(IntrinsicSize.Min)) {

        Text(
            text = "Hi",
            modifier = Modifier
                .weight(1f)
                .padding(start = 4.dp)
                .wrapContentWidth(align = Alignment.Start)
        )

        Divider(
            color = Color.Black,
            modifier = Modifier
                .fillMaxHeight()
                .width(1.dp)
        )

        Text(
            text = "there",
            modifier = Modifier
                .weight(1f)
                .padding(end = 4.dp)
                .wrapContentWidth(Alignment.End)
        )

    }
}
